home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_128 / mrbackup / filemisc.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  157 lines

  1. /* File date routines.
  2.  * Filename:    FileDates.c
  3.  * History:        (most recent change first)
  4.  *
  5.  * 09/24/87 -MRR- SetFileDate was allocating a BSTR of 68 bytes, rather
  6.  *                than using the length of the file name string.  I don't
  7.  *                have the foggiest notion why (that was DUMB!).
  8.  */
  9.  
  10. #include "exec/types.h"
  11. #include "exec/ports.h"
  12. #include "exec/io.h"
  13. #include "exec/memory.h"
  14. #include "libraries/dosextens.h"
  15. #include <stdio.h>
  16. #define AZTEC 1
  17. #ifdef AZTEC
  18. #include "functions.h"                /* aztec C include */
  19. #endif
  20.  
  21. #define ACTION_SETDATE_MODE 34L        /* Set creation date on file */
  22. #define DOSTRUE         -1L            /* AmigaDos TRUE */
  23. #define MAXARGS          7L            /* limit in packet structure
  24.                                        (dosextens.h) */
  25. #define NARGS             4L            /* Number of args for setdate */
  26.  
  27. long    sendpkt();
  28.  
  29.  
  30. /*---------------------------------------------------------------------*/
  31. /*  GetFileDate: get the datestamp the given file.                          */
  32. /*---------------------------------------------------------------------*/
  33.  
  34. BOOL GetFileDate(name, date)
  35. char   *name;
  36. register struct DateStamp  *date;
  37. {
  38.     struct FileInfoBlock   *Fib;
  39.     ULONG   FLock;
  40.     int     result;
  41.     register struct DateStamp  *d;
  42.  
  43.     if ((FLock = (ULONG)Lock(name,(long)(ACCESS_READ)))== NULL)
  44.         return FALSE;
  45.  
  46.     Fib = (struct FileInfoBlock *)
  47.         AllocMem((long)sizeof(struct FileInfoBlock),
  48.                     (long)(MEMF_CHIP|MEMF_PUBLIC));
  49.  
  50.     if (Fib == NULL )
  51.         result = FALSE;
  52.     else{
  53.         if (!Examine(FLock,Fib ))
  54.             result = FALSE;
  55.         else 
  56.             if (Fib->fib_DirEntryType > 0 )
  57.                 result = FALSE;        /* It's a directory */
  58.             else{
  59.                 d = &Fib->fib_Date;
  60.                 date->ds_Days = d->ds_Days;
  61.                 date->ds_Minute = d->ds_Minute;
  62.                 date->ds_Tick = d->ds_Tick;
  63.                 result = TRUE;
  64.             }
  65.         FreeMem((void *)Fib,(long)sizeof(struct FileInfoBlock));
  66.     }
  67.  
  68.     UnLock(FLock);
  69.     return result;
  70. }
  71.  
  72. /* Examine a pathname to determine if it is a device or directory name.
  73.  * Called with:
  74.  *        name:        pathname specification
  75.  * Returns:
  76.  *        0 =>        no
  77.  *        1 =>         yes
  78.  *       <0 =>        -<system error number>
  79.  */
  80. int
  81. IsDir(name)
  82.     char *name;
  83. {
  84.     struct FileInfoBlock   *FIB = NULL;
  85.     struct Lock *lock = NULL;    
  86.     int status;
  87.  
  88.  
  89.     if (!(FIB =
  90.         AllocMem((long)sizeof(struct FileInfoBlock),
  91.                  MEMF_CHIP|MEMF_CLEAR))) {
  92.         return -ERROR_NO_FREE_STORE;
  93.     }
  94.  
  95.     if (!(lock=Lock(name,SHARED_LOCK))) {
  96.         status = -IoErr();
  97.         goto done;
  98.     }
  99.  
  100.     if ((Examine(lock,FIB))==0){
  101.         status = -IoErr();
  102.         goto done;
  103.     }
  104.  
  105.     status = (FIB->fib_DirEntryType > 0);
  106. done:
  107.     if (FIB)
  108.         FreeMem(FIB, (long) sizeof(struct FileInfoBlock));
  109.     UnLock(lock);
  110.     return status;
  111. }
  112.  
  113. /*---------------------------------------------------------------------*/
  114. /*  SetFileDate: datestamp the given file with the given date.           */
  115. /*---------------------------------------------------------------------*/
  116.  
  117. BOOL SetFileDate(name,date )
  118. char   *name;
  119. struct DateStamp   *date;
  120. {
  121.     struct MsgPort     *task;        /* for process id handler */
  122.     ULONG   arg[4];                    /* array of arguments     */
  123.     int nameleng;
  124.     char   *bstr, *strcpy();        /* of file to be set      */
  125.     long    rc;
  126.     char   *strchr();
  127.     int     strlen();
  128.  
  129.     rc = 0;
  130.  
  131.     nameleng = strlen(name);
  132.     if (!(bstr = (char *)AllocMem((long) (nameleng + 2),MEMF_PUBLIC)))
  133.         goto exit2;
  134.  
  135.     if (!(task = (struct MsgPort *)DeviceProc(name )))
  136.         goto exit1;
  137.  
  138.  /* Dos Packet needs the filename in Bstring format */
  139.  
  140.     (void) strcpy(bstr+1, name );
  141.     *bstr = nameleng;
  142.  
  143.     arg[0]= (ULONG)NULL;
  144.     arg[1]= (ULONG)IoErr();            /* lock on parent director set by
  145.                                        DeviceProc() */
  146.     arg[2]= (ULONG)bstr >> 2;
  147.     arg[3]= (ULONG)date;
  148.     rc = sendpkt(task,ACTION_SETDATE_MODE,arg,4L );
  149.  
  150. exit1: if (bstr )
  151.         FreeMem((void *)bstr, (long) (nameleng + 2));
  152. exit2: if (rc == DOSTRUE )
  153.         return TRUE;
  154.     else
  155.         return FALSE;
  156. }
  157.